package com.event.demo.controller;

import com.event.demo.service.UserChangePasswordEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hh
 * @since 2023/3/29
 */
@RequestMapping("event")
@RestController
@RequiredArgsConstructor
public class PublishEventController {

    private final ApplicationEventPublisher applicationEventPublisher;

    @GetMapping("publish")
    public String publish(String name) {
        applicationEventPublisher.publishEvent(new UserChangePasswordEvent(name));
        System.out.println("发布接口执行完毕");
        return "success";
    }

}
